Re: [SQL] 2 Table Select - Mailing list pgsql-sql

From Herouth Maoz
Subject Re: [SQL] 2 Table Select
Date
Msg-id l03130301b376cff230ad@[147.233.159.109]
Whole thread Raw
In response to Re: [SQL] 2 Table Select  ("Oliver Elphick" <olly@lfix.co.uk>)
List pgsql-sql
At 22:34 +0300 on 27/05/1999, Oliver Elphick wrote:


>
> select c.company_id, count(j.job_id)
>    from company as c, jobs as j
>    where c.company_id = j.company_id
>    group by c.company_id;

If it's only the company_id that interests you, and not the company name or
other details in the company table, you can give up the company table
altogether. The company_id appears in the jobs table, and there is no point
in selecting c.company_id when the condition was that c.company_id is equal
to j.company_id.

In other words, if all you need is company_id, you can use:

select company_id, count(job_id)
from jobs
group by company_id;

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma




pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?
Next
From: Herouth Maoz
Date:
Subject: Re: [SQL] Does PostgreSQL have an UPDATE Function like UNIFY?